package com.xinli.xinlifm.view.adapter.find;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.xinli.xinlifm.R;
import com.xinli.xinlifm.http.bean.find.FindZhuBean;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by zz on 16-10-13.
 */

public class ZhuGridAdapter extends BaseAdapter{
    private final LayoutInflater inflater;
    private Context context;
    private List<FindZhuBean.DataBean> list;

    public ZhuGridAdapter(Context context, List<FindZhuBean.DataBean> list) {
        this.context = context;
        this.list = list;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public FindZhuBean.DataBean getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        FindZhuBean.DataBean dataBean = list.get(position);
        ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = inflater.inflate(R.layout.find_grid_item2, parent,false);
            viewHolder.zhu_fmnum = (TextView) convertView.findViewById(R.id.find_zhu_fmnum);
            viewHolder.zhu_img = (CircleImageView) convertView.findViewById(R.id.find_zhu_img);
            viewHolder.zhu_name = (TextView) convertView.findViewById(R.id.find_zhu_name);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.zhu_fmnum.setText("节目"+dataBean.getFmnum()+"");
        viewHolder.zhu_name.setText(dataBean.getUser().getNickname());
        Picasso.with(context).load(dataBean.getCover()).placeholder(R.mipmap.cover_default).into(viewHolder.zhu_img);
        return convertView;
    }

    private static class ViewHolder{
        TextView zhu_name;
        CircleImageView zhu_img;
        TextView zhu_fmnum;
    }
}
